package com.sundy.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sundy.core.Common;
import com.sundy.core.Context;
import com.sundy.core.Utility;
import com.sundy.daosupport.TeacherTblDAO;
import com.sundy.service.TeacherTbl;

public class UserPassServlet extends AbstractServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9001930781599068810L;

	public UserPassServlet() {
	}

	protected void doGet(Context context, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(context, request, response);
	}

	protected void doPost(Context context, HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String action = request.getParameter("action");
		if (action == null || action.equals("")) {
			Utility.showError(request, response, "参数错误");
			return;
		} else if (action.equals("passmodify")) {
			String password = request.getParameter("pass1");
			if (password == null || password.trim().equals("")) {
				Utility.showInfor(request, response, "密码不能设置为空！");
				return;
			}
			TeacherTblDAO dao = TeacherTblDAO
					.getFromApplicationContext(Common.applicationContext);
			TeacherTbl user = context.getCurrentUser();
			user.setPassword(password);
			dao.merge(user);
			dao.getHibernateTemplate().flush();
		}
		response.sendRedirect(request.getContextPath());
	}

}
